# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/28 14:27 
@Author  : ZhangShenao 
@File    : function_as_variable.py
@Desc    : 函数和类都可以赋值给变量
"""


# 定义一个函数
def say_hello(name: str):
    print(f'hello: {name}')


# 可以将函数赋值给一个变量,这个变量的类型就是function
say_hello_func = say_hello
# type of say_hello_func is: <class 'function'>, value is <function say_hello at 0x104c263e0>
print(f'type of say_hello_func is: {type(say_hello_func)}, value is {say_hello_func}')

# 可以通过变量调用函数
say_hello_func('LLM应用开发工程师')


# 定义一个类
class Apple:
    who_am_i: str = 'apple'


# 类也可以赋值给一个变量,这个变量就相当于类的别名(Type Alias)
apple_class = Apple
# type od apple_class is: <class 'type'>, value is: <class '__main__.Apple'>
print(f'type od apple_class is: {type(apple_class)}, value is: {apple_class}')
# 可以通过变量访问类属性
print(apple_class.who_am_i)
# 可以通过变量来实例化类
apple_instance = apple_class()
# type of apple is: <class '__main__.Apple'>, value is: <__main__.Apple object at 0x102ac2000>
print(f'type of apple is: {type(apple_instance)}, value is: {apple_instance}')
